<?php
/**
 * 创建模版文件
 */
namespace plugins\qbt_custom_model\service;
use think\Db;

class TplService{
    /**
     * 获取多图片模版
     */
    public static function get_photo_js($field_info){
        $photo = '';

        foreach ($field_info as $k=>$v){
            if($v['field_type'] == "images"){
                $photo .= '
                <script type="text/html" id="'.$v['field_name'].'-item-tpl">
                <li id="saved-image{id}">
                    <input id="'.$v['field_name'].'-{id}" type="hidden" name="'.$v['field_name'].'_urls[]" value="{filepath}">
                    <input class="form-control" id="'.$v['field_name'].'-{id}-name" type="text" name="'.$v['field_name'].'_names[]" value="{name}"
                           style="width: 200px;" title="图片名称">
                    <img id="'.$v['field_name'].'-{id}-preview" src="{url}" style="height:36px;width: 36px;"
                         onclick="imagePreviewDialog(this.src);">
                    <a href="javascript:uploadOneImage(\'图片上传\',\'#'.$v['field_name'].'-{id}\');">替换</a>
                    <a href="javascript:(function(){$(\'#saved-image{id}\').remove();})();">移除</a>
                </li>
            </script>
                ';
            }
        }

        return $photo;
    }

    /**
     * 获取多文件模版
     */
    public static function get_files_js($field_info){
        $files = '';
        foreach ($field_info as $k=>$v){
            if($v['field_type'] == "files"){
                $files .= '
                    <script type="text/html" id="'.$v['field_name'].'-item-tpl">
                    <li id="saved-'.$v['field_name'].'{id}">
                        <input id="'.$v['field_name'].'-{id}" type="hidden" name="'.$v['field_name'].'_urls[]" value="{filepath}">
                        <input class="form-control" id="file-{id}-name" type="text" name="'.$v['field_name'].'_names[]" value="{name}"
                               style="width: 200px;" title="文件名称">
                        <a id="'.$v['field_name'].'-{id}-preview" href="{preview_url}" target="_blank">下载</a>
                        <a href="javascript:uploadOne(\'文件上传\',\'#'.$v['field_name'].'-{id}\',\'file\');">替换</a>
                        <a href="javascript:(function(){$(\'#saved-'.$v['field_name'].'{id}\').remove();})();">移除</a>
                    </li>
                </script>
                ';
            }
        }
        return $files;
    }
}